package com.mob.tools.utils;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Looper;
import android.os.Message;
import com.mob.tools.MobHandlerThread;

public class LocationHelper
  implements LocationListener, Handler.Callback
{
  private int GPSTimeoutSec;
  private boolean gpsRequesting;
  private Handler handler;
  private LocationManager lm;
  private boolean networkRequesting;
  private int networkTimeoutSec;
  private Location res;

  public LocationHelper()
  {
    MobHandlerThread localMobHandlerThread = new MobHandlerThread();
    localMobHandlerThread.start();
    this.handler = new Handler(localMobHandlerThread.getLooper(), this);
  }

  private void onGPSTimeout()
  {
    this.lm.removeUpdates(this);
    this.gpsRequesting = false;
    int i = this.networkTimeoutSec;
    int j = 0;
    if (i != 0)
      j = 1;
    if ((j != 0) && (this.lm.isProviderEnabled("network")))
    {
      this.networkRequesting = true;
      this.lm.requestLocationUpdates("network", 1000L, 0.0F, this);
      if (this.networkTimeoutSec > 0)
        this.handler.sendEmptyMessageDelayed(1, 1000 * this.networkTimeoutSec);
      return;
    }
    try
    {
      notifyAll();
      this.handler.getLooper().quit();
      return;
    }
    finally
    {
    }
  }

  private void onRequest()
  {
    int i;
    int j;
    if (this.GPSTimeoutSec != 0)
    {
      i = 1;
      if (this.networkTimeoutSec == 0)
        break label84;
      j = 1;
      label18: if ((i == 0) || (!this.lm.isProviderEnabled("gps")))
        break label89;
      this.gpsRequesting = true;
      this.lm.requestLocationUpdates("gps", 1000L, 0.0F, this);
      if (this.GPSTimeoutSec > 0)
        this.handler.sendEmptyMessageDelayed(1, 1000 * this.GPSTimeoutSec);
    }
    label84: label89: 
    do
    {
      return;
      i = 0;
      break;
      j = 0;
      break label18;
      if ((j == 0) || (!this.lm.isProviderEnabled("network")))
        break label150;
      this.networkRequesting = true;
      this.lm.requestLocationUpdates("network", 1000L, 0.0F, this);
    }
    while (this.networkTimeoutSec <= 0);
    this.handler.sendEmptyMessageDelayed(1, 1000 * this.networkTimeoutSec);
    return;
    try
    {
      label150: notifyAll();
      this.handler.getLooper().quit();
      return;
    }
    finally
    {
    }
  }

  public Location getLocation(Context paramContext)
    throws Throwable
  {
    return getLocation(paramContext, 0);
  }

  public Location getLocation(Context paramContext, int paramInt)
    throws Throwable
  {
    return getLocation(paramContext, paramInt, 0);
  }

  public Location getLocation(Context paramContext, int paramInt1, int paramInt2)
    throws Throwable
  {
    return getLocation(paramContext, paramInt1, paramInt2, true);
  }

  public Location getLocation(Context paramContext, int paramInt1, int paramInt2, boolean paramBoolean)
    throws Throwable
  {
    int i = 1;
    this.GPSTimeoutSec = paramInt1;
    this.networkTimeoutSec = paramInt2;
    this.lm = ((LocationManager)paramContext.getSystemService("location"));
    if (this.lm == null)
      return null;
    while (true)
    {
      try
      {
        this.handler.sendEmptyMessageDelayed(0, 50L);
        wait();
        if ((this.res == null) && (paramBoolean))
        {
          if (paramInt1 != 0)
          {
            j = i;
            if (paramInt2 == 0)
              break label127;
            if ((j == 0) || (!this.lm.isProviderEnabled("gps")))
              break label133;
            this.res = this.lm.getLastKnownLocation("gps");
          }
        }
        else
          return this.res;
      }
      finally
      {
      }
      int j = 0;
      continue;
      label127: i = 0;
      continue;
      label133: if ((i != 0) && (this.lm.isProviderEnabled("network")))
        this.res = this.lm.getLastKnownLocation("network");
    }
  }

  public boolean handleMessage(Message paramMessage)
  {
    if (paramMessage.what == 0)
      onRequest();
    while (true)
    {
      return false;
      if (this.gpsRequesting)
      {
        onGPSTimeout();
        continue;
      }
      if (!this.networkRequesting)
        continue;
      this.lm.removeUpdates(this);
      try
      {
        notifyAll();
        this.handler.getLooper().quit();
      }
      finally
      {
      }
    }
  }

  public void onLocationChanged(Location paramLocation)
  {
    try
    {
      this.lm.removeUpdates(this);
      this.res = paramLocation;
      notifyAll();
      this.handler.getLooper().quit();
      return;
    }
    finally
    {
    }
  }

  public void onProviderDisabled(String paramString)
  {
  }

  public void onProviderEnabled(String paramString)
  {
  }

  public void onStatusChanged(String paramString, int paramInt, Bundle paramBundle)
  {
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.mob.tools.utils.LocationHelper
 * JD-Core Version:    0.6.2
 */